package com.xf.lastmall.order.api.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;


@Data
@ApiModel
public class PageInfo implements Serializable {

    @ApiModelProperty(hidden = true)
    private int defaultPageNo = 1;

    @ApiModelProperty(hidden = true)
    private int defaultPageSize = 20;

    @ApiModelProperty(value = "当前页")
    private int pageNum;

    @ApiModelProperty(value = "页长度")
    private int pageSize;

    /**
     * limit n,m  对应n
     */
    @ApiModelProperty(hidden = true)
    private int skip;

//    /**
//     * ASC, DESC;
//     */
//    @ApiModelProperty(value = "升序ASC,降序DESC")
//    private Sort.Direction sortBy;

    @ApiModelProperty(value = "排序字段")
    private String orderByField;


    public int getPageNum() {
        return pageNum <= 0 ? defaultPageNo : pageNum;
    }

    public int getPageSize() {
        return pageSize <= 0 ? defaultPageSize : pageSize;
    }

    public int getPageSize(int defaultValue) {
        return pageSize == 0 ? defaultValue : pageSize;
    }

    public int getSkip() {
        skip = (getPageNum() - 1) * getPageSize();
        return skip;
    }
}
